<template>
  <div style="width: 100%;height: 100%;overflow-y: auto;" ref="content_outer">

  </div>
</template>

<script>
export default {
  props: ['__iframe'],
  data(){
    return {
      text: '# 说明文档'
    }
  },
  methods: {
  },
  mounted() {
    let app = this;
    if (!this.__iframe) window['app'] = this;

    // 后台返回的字段配置，里面包含了 validate 验证规则
    let param = {
      str_5: {label:'组件默认值',name:'str_5',type:'text_one',validate:["string","size:5"]},
      must: {label:'组件默认值',name:'must',type:'text_one',validate:["required","regex:/^1\\d{10}$/"]},
      int_3: {label:'组件默认值',name:'int_3',type:'text_one',validate:["integer", "min:3"]},
    }

    // 表单数据，用户填写收集到的
    let data = {
      "str_5": "12345",
      "must": "18312345678",
      "int_3": "4",
      "test": "test", //
    }
    let rule = {}
    Object.values(param).forEach(row=>{
      rule[row.name] = typeof row.validate == 'string' ? JSON.parse(row.validate) : row.validate;
    })

    try {
      let res = app.laravel_validate(data, rule);
      console.log(res); //验证规则过滤后的结果
    } catch (e) {
      console.log(e.errors, "error");
    }

  }
}
</script>

<style scoped>

</style>